package com.sdleyou.treepro.common.interceptor;

import com.sdleyou.treepro.common.context.UserContext;
import com.sdleyou.treepro.common.service.LastRequestTimeManager;
import com.sdleyou.treepro.system.security.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class RequestTimeInterceptor implements HandlerInterceptor {

    @Autowired
    private LastRequestTimeManager lastRequestTimeManager;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
//        String requestURI = request.getRequestURI();
//        if(requestURI.endsWith("/user/login")){
//            return true;
//        }
//        String user_id = request.getParameter("user_id");
//        if(user_id!=null){
//            lastRequestTimeManager.update(user_id);
//        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
    }
}